package com.github.skystardust.lotteryex.utils;

import com.github.skystardust.lotteryex.LotteryEX;
import org.bukkit.command.CommandSender;

import java.util.function.Supplier;

public class MessageUtils<T extends CommandSender> {
    private T receiver;
    private boolean prefixFlag;

    public MessageUtils(T receiver, boolean prefixFlag) {
        this.receiver = receiver;
        this.prefixFlag = prefixFlag;
    }

    public MessageUtils(T receiver) {
        this(receiver, true);
    }

    public MessageUtils() {
    }

    public MessageUtils<T> info(Supplier<String> stringSupplier) {
        String content = stringSupplier.get();
        if (prefixFlag) {
            receiver.sendMessage(LotteryEX.getPluginPrefix() + content);
        } else {
            receiver.sendMessage(content);
        }
        return this;
    }

    public MessageUtils<T> info(String string) {
        if (prefixFlag) {
            receiver.sendMessage(LotteryEX.getPluginPrefix() + string);
        } else {
            receiver.sendMessage(string);
        }
        return this;
    }

    public MessageUtils<T> error(String string) {
        if (prefixFlag) {
            receiver.sendMessage(LotteryEX.getPluginPrefix() + "§c" + string);
        } else {
            receiver.sendMessage("§c" + string);
        }
        return this;
    }

    public MessageUtils<T> error(Supplier<String> string) {
        if (prefixFlag) {
            receiver.sendMessage(LotteryEX.getPluginPrefix() + "§c" + string.get());
        } else {
            receiver.sendMessage("§c" + string.get());
        }
        return this;
    }

    public MessageUtils<T> warn(String string) {
        if (prefixFlag) {
            receiver.sendMessage(LotteryEX.getPluginPrefix() + "§e" + string);
        } else {
            receiver.sendMessage("§e" + string);
        }
        return this;
    }

    public MessageUtils<T> warn(Supplier<String> string) {
        if (prefixFlag) {
            receiver.sendMessage(LotteryEX.getPluginPrefix() + "§e" + string.get());
        } else {
            receiver.sendMessage("§e" + string.get());
        }
        return this;
    }

    public T getReceiver() {
        return receiver;
    }

    public MessageUtils<T> setReceiver(T receiver) {
        this.receiver = receiver;
        return this;
    }

    public boolean isPrefixFlag() {
        return prefixFlag;
    }

    public MessageUtils<T> setPrefixFlag(boolean prefixFlag) {
        this.prefixFlag = prefixFlag;
        return this;
    }

}
